package com.keqiongzc.module_login

import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.everyline.lib_base.base.BaseViewModel
import com.everyline.lib_base.ext.parseState
import com.everyline.lib_common.base.BaseActivity
import com.everyline.lib_common.bean.UserInfoBean
import com.everyline.lib_common.router.RouterPath
import com.everyline.lib_common.service.LoginService
import com.keqiongzc.module_login.databinding.LoginActivityLoginBinding

/**
 * Created by on 2021/2/26.
 * 天天挂线
 *  746608431@qq.com
 *  描述:TODO
 */

@Route(path = RouterPath.Login.PATH_LOGIN)
class LoginActivity : BaseActivity<BaseViewModel, LoginActivityLoginBinding>() {
    private val requestLoginCodeModel by viewModels<RequestLoginCodeModel>()


    private var randNum: String = ""

    override fun initListener() {
        mViewBinding.tv1.setOnClickListener {
//            val userInfoBean = UserInfoBean(10, "李吸纳生", "", "", "aaaaaaaaaaaaaaa", "")
//            UserManager.saveUser(userInfoBean)

//            ARouter.getInstance().build(RouterPath.Home.PATH_HOME).navigation()
            driverLoginByMobile()

        }

    }

    private fun driverLoginByMobile() {
        val map = hashMapOf<String, String>()
        map["mobile"] = "17839930811"
        map["smsCode"] = "705705"
        map["randNum"] = randNum
        map["isNew"] = "1"
        requestLoginCodeModel.driverLoginByMobile(map)
    }

    override fun createObserver() {
        requestLoginCodeModel.userBeanData.observe(this, Observer { data ->
            parseState(data, {
                it?.let {
                    val userInfoBean = UserInfoBean(
                        it.auditStatus,
                        it.color,
                        it.carNo,
                        it.driverMobile,
                        it.driverName,
                        it.model,
                        it.jwtToken,
                        it.driverHeadImg,
                        it.brand,
                        it.amapTid,
                        it.driverId,
                        it.amapSid
                    )
                    UserManager.saveUser(userInfoBean)
                    ARouter.getInstance().build(RouterPath.Home.PATH_HOME).navigation()
                }

            }, {})


        })

    }

    override fun getTitleBar(): Int = 0

    override fun initView(savedInstanceState: Bundle?) {
        ARouter.getInstance().inject(this)
    }

    override fun initData() {

    }

    override fun getLayoutResId(): Int = R.layout.login_activity_login
}